//
//  SAPSecondFindTableViewCell.m
//  CarsHome
//
//  Created by dapeng on 15/12/5.
//  Copyright © 2015年 dapeng. All rights reserved.
//

#import "SAPSecondFindTableViewCell.h"
#import "Theme-PrefixHeader.pch"
@implementation SAPSecondFindTableViewCell
- (void)dealloc {
    [super dealloc];
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
  
    }return self;
}


- (void)layoutSubviews {
    [super layoutSubviews];
    for (int i = 0; i < 8; i++) {
        UIView *views = (UIView *)[self viewWithTag:100 + i];
        
        
        UIImageView *sellImage = (UIImageView *)[self viewWithTag:110 + i];
        sellImage.frame = CGRectMake(0, 0, SCREEN_SIZE.width / 2, SCREEN_SIZE.width / 2 - 70);
        UILabel *title = (UILabel *)[self viewWithTag:120 + i];
        title.frame = CGRectMake(10, SCREEN_SIZE.width / 2 - 70, SCREEN_SIZE.width / 2, 30);
        UILabel *adinfo = (UILabel *)[self viewWithTag:130 + i];
        adinfo.frame = CGRectMake(10, SCREEN_SIZE.width / 2 - 40, SCREEN_SIZE.width / 2, 20);
        UILabel *state = (UILabel *)[self viewWithTag:140 + i];
        state.frame = CGRectMake(10, SCREEN_SIZE.width / 2 - 20, SCREEN_SIZE.width / 2, 15);
        UILabel *fctprice = (UILabel *)[self viewWithTag:150 + i];
        fctprice.frame = CGRectMake(70, SCREEN_SIZE.width / 2 - 20, SCREEN_SIZE.width / 2, 12);
                if (i % 2 == 0) {
            views.frame = CGRectMake(0, SCREEN_SIZE.width * i / 4, SCREEN_SIZE.width / 2, SCREEN_SIZE.width / 2 + 30);
        }else {
            views.frame = CGRectMake(SCREEN_SIZE.width / 2, SCREEN_SIZE.width * (i - 1) / 4, SCREEN_SIZE.width / 2, SCREEN_SIZE.width / 2 + 30);
        }
        
    }
}
- (void)setOneModel:(SAPFindOneModel *)oneModel {
    if (_oneModel != oneModel) {
        [_oneModel release];
        _oneModel = [oneModel retain];
    }

    for (int i = 0; i < 8; i++) {
        SAPFindTwoModel *twoModel = oneModel.listArray[i];
        UIView *views = [[UIView alloc] initWithFrame:CGRectZero];
        views.tag = 100 + i;
        
        UIImageView *sellImage = [[UIImageView alloc] initWithFrame:CGRectZero];
        [sellImage sd_setImageWithURL:[NSURL URLWithString:twoModel.logo] placeholderImage:[UIImage imageNamed:@"zhanwei.png"]];
        sellImage.tag = i + 110;
        
        UILabel *title = [[UILabel alloc] initWithFrame:CGRectZero];
        title.text = twoModel.title;
        title.backgroundColor = [[ConfigurationTheme shareInstance] getThemeColorWithName:@"ygColor"];
        title.tag = i + 120;
        
        UILabel *adinfo = [[UILabel alloc] initWithFrame:CGRectZero];
        adinfo.text = twoModel.adinfo;
        adinfo.font = [UIFont systemFontOfSize:12];
        
        
        adinfo.tag = i + 130;
        
        UILabel *state = [[UILabel alloc] initWithFrame:CGRectZero];
        state.text = twoModel.prices;
        state.font = [UIFont systemFontOfSize:15];
        state.tag = i + 140;
        
        UILabel *fctprice = [[UILabel alloc] initWithFrame:CGRectZero];
        fctprice.text = twoModel.fctprice;
        fctprice.font = [UIFont systemFontOfSize:12];
        fctprice.tag = i + 150;
        
     
        NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
        NSString *passWord = [user objectForKey:@"nightModel"];
        
        if (!(passWord == nil) && [passWord isEqualToString:@"day"]) {
            state.textColor = RGB(153.0,153.0,153.0,1.0f);
            adinfo.textColor = RGB(153.0,153.0,153.0,1.0f);
            title.textColor = RGB(153.0,153.0,153.0,1.0f);
            fctprice.textColor = RGB(153.0,153.0,153.0,1.0f);
            self.backgroundColor = [UIColor colorWithWhite:0.126 alpha:1.000];
            
        }else{
            self.backgroundColor = [UIColor whiteColor];
            
        }

        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(clickAction:)];
        [views addGestureRecognizer:tap];
        [views addSubview:state];
        [views addSubview:adinfo];
        [views addSubview:sellImage];
        [views addSubview:title];
        [views addSubview:fctprice];
        [self addSubview:views];
        [sellImage release];
        [title release];
        [adinfo release];
        [state release];
        [views release];
        [fctprice release];
    }
    
}
- (void)clickAction:(UITapGestureRecognizer *)sender {
    _count = sender.view.tag - 100;
    [self.delegate passSecondFindValue:_count];
    
}
- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
